﻿using System;
using System.Collections.Generic;
using System.Text;

using OgilvyOne.Borad.IDAL;
using OgilvyOne.Borad.Factory;
using System.Data;

namespace OgilvyOne.Borad.BLL
{
    public class PreOrderBLL
    {
        IDALPreOrder use = PreOrderFactory.Creat();
        public int Insert(string img,string name,string sex, string mobile, string email, string province, string city, string dealer, string budget, string mention, string capcity, string carModel, string carColor, string carSeat, string source,string channel)
        {
            int flag = use.Add(name, sex, mobile, email, province, city, dealer, budget, mention, capcity, carModel, carColor, carSeat, source, channel);
            if (flag > 0)
            {
                try
                {
                    int res = SendMailTo(img,"email", name, sex, mobile, email, dealer, budget, mention, capcity, carModel, carColor, carSeat);
                }
                catch (Exception ex)
                {
                    return flag;
                }
            }
            return flag;
        }

        public int IsExist(string email)
        {
            return use.IsExist(email);
        }

        //发送邮件
        public int SendMailTo(string img,string fileName,string name, string sex, string mobile, string email,  string dealer, string budget, string mention, string capcity, string carModel, string carColor, string carSeat)
        {
            //string sendHtmlName = "email";
            string emailbody = MailService.generateEmail(img,fileName, name, sex, mobile, email, dealer, budget, mention, capcity, carModel, carColor, carSeat);

            bool flag = MailService.sendMail(email, emailbody);
            if (flag)
                return 1;
            else
                return 0;
        }

        /// <summary>
        /// 获取字典表
        /// </summary>
        /// <returns></returns>
        public DataSet GetAll()
        {
            return use.Query();
        }

        /// <summary>
        /// 获取字典表中省份
        /// </summary>
        /// <returns></returns>
        public DataTable GetProvince()
        {
            return use.GetProvince();
        }
    }
}
